SharePoint key word query, how does the "Query Text" query special character in a query variable?

I have a no code sandbox solution, in a content by search web part, I want to return pages from the library except the page I am visiting.
 
I have 2 pages:
Page A, the title is: Page title without special character
Page B, the title is: Page title with special character "a b c d ..."

And then I use Title<>{Page.Title} in the query text of the CSWP.

While I visit Page A, the CSWP returns Page B, it works as expected.
But while I visit Page B, the CSWP returns nothing, expected result should be Page A. I just consider, whether the special characters in the Title of Page B breaks the query text.

I can not find similar topics in the forum, Does anyone have idea?

Many thanks!



  • Edited by Claud _ Wednesday, December 03, 2014 10:14 AM format the content
December 3rd, 2014 1:12pm

Hi Claud,

When use the special character double quotation marks (i.e. "") for page title and Title<>{Page.Title} in query builder, we will have 4 double quotation marks in query text, first two will mach, so it will not work for CSWP in page with special character ". 

For resolving this issue, we can use single quotation marks(i.g. '') instead of double quotation marks in the page title, then it will work, so for Page B, we can use it like format below.

Page B, the title is: Page title with special character 'a b c d ...'

Thanks,
Daniel Yang
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com. 

Free Windows Admin Tool Kit Click here and download it now
December 5th, 2014 6:13am

Thank you for your feedback, Daniel.

I have some updates, and found the root cause: if the field value contains special characters, the CSWP will not render the double quotation marks around the field value.

View the page html source, and then find the text "QueryModification", you will see what happen:

Query Text Input: Title<>{Page.Title}

1. While the page title is "Test Page 1" (without special character), the rendered query text is Title<>\"Test Page 1\". It works as expected.
2. While the page title is "Test-Page-1" (with special character "-", of cause we have more special characters on production), the rendered query text is Title<>Test-Page-1.  The double quotation marks are not rendered by the CSWP, so the query text are broken. It does not work as expected.

If I make the query text as Title<>"{Page.Title}"

1. While the page title is "Test Page 1", the rendered query text is Title<>\"\"Test Page 1\"\". It does NOT work since the quotes are duplicated (no sure why CSWP duplicates the quota mark),
2. While the page title is "Test-Page-1", the rendered query text is Title<>\"Test-Page-1\".  Quotes are correct, but it does NOT work as expected still.

The expected rendered query text (view from the html source) should be Title<>\"Test\\\-Page\\\-1\". (Here is test url: <a href="http://server/_api/search/query?querytext='Title<>"Test%5c%5c%5c-Page%5c%5c%5c-1"'&rowlimit=10">http://server/_api/search/query?querytext='Title<>"Test%5c%5c%5c-Page%5c%5c%5c-1"'&rowlimit=10)

From the above information, I can say the CSWP not handle the special character correctly ("\" is not inserted before any special charactor).

Is there any setting in CSWP can be used to resolve above problem?

February 16th, 2015 9:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics